package com.qianfeng.openapi.managerplateform.service.impl;

import com.github.pagehelper.PageHelper;
import com.qianfeng.openapi.managerplateform.dao.UserTokenDao;
import com.qianfeng.openapi.managerplateform.pojo.ResponseData;
import com.qianfeng.openapi.managerplateform.pojo.UserToken;
import com.qianfeng.openapi.managerplateform.service.UserTokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserTokenServiceImpl implements UserTokenService {
    @Autowired
    private UserTokenDao userTokenDao;
    ResponseData responseData = new ResponseData();
    @Override
    public ResponseData getAllUserToken(int page,int limitf) {
        PageHelper.startPage(page, limitf);
        List<UserToken> allUserToken = userTokenDao.getAllUserToken();
        if(allUserToken!=null){
            responseData.setCode(0);
            responseData.setMsg("true");
            responseData.setData(allUserToken);
            return responseData;
        }
        responseData.setCode(1);
        responseData.setMsg("false");

        return responseData;
    }

    @Override
    public boolean delUserToken(int[] ids) {
        for (int id:ids){
            int i = userTokenDao.delUserToken(id);
            if(i==0){
                return false;
        }

        }
        return true;
    }

    @Override
    public boolean updateUserToken(UserToken userToken) {
        int i = userTokenDao.updateUserToken(userToken);
        if(i>0){
            return true;
        }
        return false;
    }
}
